﻿@{
    Layout = null;
}
@model ElingOA6_Admin_DSJCJ.Model.Ad
<!DOCTYPE html>

<html>


<head>
<base target="_self" />
@Html.Partial("LoadPanelPartial")
   @if (false)
   {
        <script src="../../../../Scripts/jquery-vsdoc.js" type="text/javascript"></script>
        <script src="../../../../Scripts/ASPxScriptIntelliSense.js" type="text/javascript"></script>
        <script src="../../../../Scripts/json2.js" type="text/javascript"></script>  
   }
    <link href="@Url.Content("~/Content/Site.css", true)" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/jquery-ui-tabs.css", true)" rel="stylesheet" type="text/css" />

    <script src="@Url.Content("~/Scripts/jquery.min.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/jquery-ui.min.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/FloatDiv.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/PageCommon.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/json2.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/CJL.0.1.min.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/ImagePreview.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Common/GetRootPath.ashx", true)" type="text/javascript"></script>

    @Html.DevExpress().GetStyleSheets(

        new StyleSheet { ExtensionType = ExtensionType.ListBox, Theme = DevExpressHelper.Theme }
)
    @Html.DevExpress().GetScripts(
        new Script { ExtensionType = ExtensionType.ListBox }
)

    <script type="text/javascript">


        $(document).ready(function () {
            var hdjsAlert = $("#hidMessage").val();
            var hdjsAlert2 = $("#hidIsClose").val();
            if (hdjsAlert != "") {
                alert(hdjsAlert);
                if (hdjsAlert2 == "Y") {
                    window.returnValue = 'SUCCESS';
                    window.close();
                }
            }

            if ($("#hidImgYWidth").val() == "0" && $("#hidImgYHeight").val() == "0" && $("#hdold").val() == "" && $("#hdsvr").val() == "" && $("#hdtype").val() == "Edit")
             {
                 ASPxClientCheckBox.Cast("UpdateImg").SetChecked(false);
                 FAdWidth.SetEnabled(false);
                 FAdHeight.SetEnabled(false);
                 picUpload.SetEnabled(false);
                 document.getElementById("picUpload").disabled = "disabled";

                 steFu(document.getElementById("picUpload"));
                 setReset();

            }

        });

        /*取消*/
        function cancel() {
            window.close();
                       
        }

        function ok() {
            var adcd = FAdcd.GetText();
            if (pd(adcd)) {
                if ($('#hidAdNo').val() == "")//增加时判断编号是否已存在
                {
                    $.ajax({
                        type: 'POST',
                        url: rootPath + '/Admin/Ad/ExistsAd',
                        data: { fAdcd: adcd },
                        success: function (result) {
                            if (result == "N") {
                                save(adcd);
                            } else if (result == "Y") {
                                FAdcd.SetErrorText("广告编号已存在");
                                FAdcd.SetIsValid(false);
                            } else {
                                alert("判断编号是否已存在参数错误");
                            }
                        }
                    });
                } else {
                    save(adcd);
                }
            }
        }

        //保存
        function save(adcd) {
            
//            var client = ASPxClientCheckBox.Cast("UpdateImg");
//            var clientUpload = ASPxClientUploadControl.Cast("picUpload");
//            if (client.GetChecked() == true && clientUpload.GetText() == "") {
//                alert("请上传图片！")
//                return;
//             }
            form1.submit();
        }



         function pd(adcd) {
            var bl = true;
            if (adcd == null || ASPxClientUtils.Trim(adcd) == "") 
            {
                FAdcd.SetErrorText("请填写广告编码");
                FAdcd.SetIsValid(false);
                bl = false;
            }


            if (bl) {
                var pic = picUpload.GetText();
                pic = pic.substring(pic.lastIndexOf("."));
                pic = pic.toLowerCase();
                if (pic != "" && pic != ".jpg" && pic != ".jpeg" && pic != ".jpe" && pic != ".gif" && pic != ".bmp") {
                    alert("请上传以下类型图片  .jpg .jpeg .jpe .gif .bmp");
                    bl = false;
                }
            }
   
            return bl;
            }


            function isUpdateImg(s ,e) {
                if (s.GetChecked()) {
                    FAdWidth.SetEnabled(true);
                    FAdHeight.SetEnabled(true);
                    picUpload.SetEnabled(true);
                   document.getElementById("picUpload").disabled = "";
            } else {
                FAdWidth.SetEnabled(false);
                FAdHeight.SetEnabled(false);
                picUpload.SetEnabled(false);
                document.getElementById("picUpload").disabled = "disabled";

                steFu(document.getElementById("picUpload"));
                setReset();

            }

        }
        //设置选择的不是图片时，各个内容重置
        function setReset() {
            document.getElementById("FAdWidth").value = 0;
            document.getElementById("FAdHeight").value = 0;
            document.getElementById("image").src = "";
            document.getElementById("image").style.width = "0px";
            document.getElementById("image").style.height = "0px";
        }

        //还原图片高宽
        function resetImg() {
            var imgWidth = $("#hidImgYWidth").val();
            var imgHeight = $("#hidImgYHeight").val();

            ASPxClientTextBox.Cast("FAdWidth").SetText(imgWidth);
            ASPxClientTextBox.Cast("FAdHeight").SetText(imgHeight);

            document.getElementById("image").style.width = imgWidth + "px";
            document.getElementById("image").style.height = imgHeight + "px";


        }
        //状态改变时，是否锁定
        function editModel(t) {
            var strSrc = t.src;
            var t1 = strSrc.lastIndexOf("/");
            var imgNmae = strSrc.substring(t1 + 1);
            if (imgNmae == "locked.gif") {
                t.alt = "解锁";
                t.src = strSrc.substring(0, t1 + 1) + "unlocked.gif";
                $("#hidModel").val(2); //解锁           
            } else {
                t.alt = "锁定";
                t.src = strSrc.substring(0, t1 + 1) + "locked.gif";
                $("#hidModel").val(1); //锁定
            }
        }


        //宽度改变时
        function widthChange(s,e) {
            var strValue = s.GetText();
            strValue = strValue.replace(/\D/g, '');
            if (strValue == "") {
                strValue = 0;
            }

            var model = $("#hidModel").val(); 
            if (model == 1) {//锁定
                var yHeight = document.getElementById("hidImgYHeight").value;
                var yWidth = document.getElementById("hidImgYWidth").value;
                var imgHeight = 0;
                if (yWidth != 0) {
                    imgHeight = Math.round(yHeight * strValue / yWidth);
                }

                document.getElementById("image").style.width = strValue + "px";
                document.getElementById("image").style.height = imgHeight + "px";

                FAdHeight.SetText(imgHeight);
            } else {
                document.getElementById("image").style.width = strValue + "px";
            }

            ///document.getElementById("FAdWidth").value = strValue;
            s.SetText(strValue);


        }

        //高度改变时
        function heightChange(s,e) {
            var strValue = s.GetText();
            strValue = strValue.replace(/\D/g, '');
            if (strValue == "") {
                strValue = 0;
            }

            var model = document.getElementById("hidModel").value;
            if (model == 1) {//锁定
                var yHeight = document.getElementById("hidImgYHeight").value;
                var yWidth = document.getElementById("hidImgYWidth").value;
                var imgWidth = 0;
                if (yHeight != 0) {
                    imgWidth = Math.round(yWidth * strValue / yHeight);
                }
                document.getElementById("image").style.height = strValue + "px";
                document.getElementById("image").style.width = imgWidth + "px";
                FAdWidth.SetText(imgWidth);
            } else {
                document.getElementById("image").style.height = strValue + "px";
            }
            s.SetText(strValue);
        }

        //把上传控件值设为空
        function steFu(obj) {
            var nf = obj.cloneNode(true);
            nf.value = '';
            obj.parentNode.replaceChild(nf, obj);
        }


        $(function () {
            if ($("#hidQP").val() == "1") {
                ASPxClientComboBox.Cast("FAdProp").RemoveItem(4);
            }
            if ($("#hidRight").val() == "1") {
                ASPxClientComboBox.Cast("FAdProp").RemoveItem(3);
            } 
            if ($("#hidLeft").val() == "1") {
                ASPxClientComboBox.Cast("FAdProp").RemoveItem(2);
            }
        });


        //图片预览
        function previewImg() {
            var clientlogoUploadObj = ASPxClientUploadControl.Cast("picUpload");
            if (clientlogoUploadObj.GetText() != "") {
                var extend = clientlogoUploadObj.GetText().substring(clientlogoUploadObj.GetText().lastIndexOf(".") + 1).toLowerCase();
                var AdProp = ASPxClientComboBox.Cast("FAdProp").GetText();
                if (AdProp != "2")//不是图片/flash广告
                {
                    if (!(extend == "bmp" || extend == "jpg" || extend == "gif" || extend == "jpeg")) {
                        alert("请上传图片文件!");
                        setReset();
                        clientlogoUploadObj.ClearText();
                        return false;
                    }
                } else {
                    if (!(extend == "bmp" || extend == "jpg" || extend == "gif" || extend == "jpeg" || extend == "swf")) {
                        alert("请上传图片或Flash文件!");
                        setReset();
                        clientlogoUploadObj.ClearText();
                        return false;
                    }

                }

                var ip = new ImagePreview($$("picUpload_TextBox0_Input"), $$("image"), {
                });
                ip.onShow = function () {
                    var imgWidth = ip.img.style.width.replace("px", "");
                    var imgHeight = ip.img.style.height.replace("px", "");
                    setImage(imgWidth, imgHeight);
                }

                ip.img.src = ImagePreview.TRANSPARENT;
                ip.preview();
            }
            else {
                $("#image").attr("src", "");
            }
            $('#image').css("height", "100px");
            $('#image').css("width", "100px");

        }
        function setImage(imgWidth, imgHeight) {
            document.getElementById("hidImgYWidth").value = imgWidth;
            document.getElementById("hidImgYHeight").value = imgHeight;

            ASPxClientTextBox.Cast("FAdWidth").SetText(imgWidth);
            ASPxClientTextBox.Cast("FAdHeight").SetText(imgHeight);
        }


        function flashOrImg(s,e) {
            var obj = ASPxClientUploadControl.Cast("picUpload");
            var extend = obj.GetText().substring(obj.GetText().lastIndexOf(".") + 1).toLowerCase();
            if (extend == "") {
                var adpropVlaue = $("#hidAdProp").val();
                if (adpropVlaue == "2") {
                    alert("flash不能在该广告性质下发布!");
                    ASPxClientComboBox.Cast("FAdProp").SetValue("2");
                }
            } else if (extend == "swf") {
                alert("flash不能在该广告性质下发布!");
                ASPxClientComboBox.Cast("FAdProp").SetValue("2");
            }
        }

    </script>

</head>
<body>
@using (Html.BeginForm("Save", "Ad", FormMethod.Post, new { id = "form1" }))
{
        
        <table class="tableForm" align = "center" width="100%" >
            <tr>
                <th width="30%">
                   广告编码:</th>
                    <td class="tdClass">
                    @Html.DevExpress().TextBox(settings =>
               {
                   settings.Name = "FAdcd";
                   settings.Width = System.Web.UI.WebControls.Unit.Percentage(96);
                   settings.Text = Model.FAdcd;
                   settings.Enabled = (bool)ViewData["blad"];
                   settings.Properties.ValidationSettings.EnableCustomValidation = true;
               }).GetHtml()       
                        @Html.Hidden("hidAdNo", Model.FAdcd)          
                </td>
            </tr>
            <tr>
                <th>
                    广告名称:</th>
                <td class="tdClass">
                    @Html.DevExpress().TextBox(settings =>
               {
                   settings.Name = "FAdName";
                   settings.Width = System.Web.UI.WebControls.Unit.Percentage(96);
                   settings.Text = Model.FAdName;
                   settings.Properties.ValidationSettings.EnableCustomValidation = true;
               }).GetHtml()
                </td>
            </tr>
             <tr>
                <th>
                    广告性质:</th>
                <td class="tdClass">
                    @Html.DevExpress().ComboBox(settings =>
               {
                   settings.Name = "FAdProp";
                   settings.Properties.DropDownStyle = DropDownStyle.DropDownList;
                   settings.Properties.ClientSideEvents.ValueChanged = "function(s,e){flashOrImg()}";
               }).BindList(new List<SelectListItem> 
                        { 
                            new SelectListItem { Text = "浮动图标", Value = "1" }, 
                            new SelectListItem { Text = "图片/flash广告", Value = "2" },
                            new SelectListItem { Text = "对联广告(左)", Value = "3" },
                            new SelectListItem { Text = "对联广告(右)", Value = "4" },
                            new SelectListItem { Text = "全屏广告", Value = "5" } 
                        }).Bind(Model.FAdProp).GetHtml()
                </td>
            </tr>
            <tr>
                <th>
                    广告数据类型：</th>
                <td class="tdClass">
                    @Html.DevExpress().ComboBox(settings =>
               {
                   settings.Name = "FDataType";
                   settings.Properties.DropDownStyle = DropDownStyle.DropDownList;
                   settings.Enabled = (bool)ViewData["blac"];
               }).BindList(new List<SelectListItem> 
                        { 
                            new SelectListItem { Text = "用户数据", Value = "U" }, 
                            new SelectListItem { Text = "系统数据", Value = "S" }
                        }).Bind(Model.FDataType).GetHtml()
                </td>
            </tr>
            <tr>
                <th>
                    广告URL:</th>
                <td class="tdClass">
                    @Html.DevExpress().TextBox(settings =>
               {
                   settings.Name = "FAdUrl";
                   settings.Width = System.Web.UI.WebControls.Unit.Percentage(96);
                   settings.Text = Model.FAdUrl;
                   settings.Properties.ValidationSettings.EnableCustomValidation = true;
               }).GetHtml()
                </td>
            </tr>
             <tr>
                <th>
                    广告是否启用:</th>
                <td class="tdClass">
                     @Html.DevExpress().RadioButtonList(settings =>
                {
                    settings.Name = "FIsUse";
                    settings.Properties.RepeatLayout = System.Web.UI.WebControls.RepeatLayout.Table;
                    settings.Properties.RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;
                    settings.Properties.RepeatColumns = 2;
                }).BindList(new List<SelectListItem> { 
                            new SelectListItem { Text = "启用", Value = "1"}, 
                            new SelectListItem { Text = "不启用", Value = "0" } 
                        }).Bind(Model.FIsUse.ToString()).GetHtml()
                </td>
            </tr>
            <tr>
            <td colspan="2">
                <fieldset style="padding: 3px; margin: 3px;">
                     <legend style="color: #06c;">
                            @Html.DevExpress().CheckBox(settings =>
                       {
                           settings.Name = "UpdateImg";
                           settings.Checked = true;
                           settings.Text = "上传";
                           settings.Properties.ClientSideEvents.CheckedChanged = "function (s, e){ isUpdateImg(s, e)}";
                       }
                            ).GetHtml()
                            
                            </legend>
                            <table width="90%">
                                <tr>
                                <th width="10%">
                                    上传:
                                </th>
                                <td colspan="2" class="tdClass">                                
                                    @Html.DevExpress().UploadControl(
                                        settings =>
                                        {
                                            settings.Name = "picUpload";
                                            settings.BrowseButton.Text = "浏览";
                                            settings.ClearFileSelectionImage.ToolTip = "清除选择";
                                            settings.ShowProgressPanel = true;
                                            //settings.AdvancedModeSettings.EnableMultiSelect = true;
                                            settings.ValidationSettings.MaxFileSize = 20971520;
                                            settings.ValidationSettings.AllowedFileExtensions = new string[] { ".jpg", ".jpeg", ".jpe", ".gif", ".png" };
                                            settings.ShowUploadButton = false;
                                            settings.ClientSideEvents.TextChanged = "function(s,e){previewImg()}";
                                        }).GetHtml()
                                </td>
                            </tr>
                            <tr>
                                <th>
                                    宽:
                                </th>
                                <td width="10" align="left" class="tdClass">
                                     @Html.DevExpress().TextBox(settings =>
                                {
                                    settings.Name = "FAdWidth";
                                    settings.Width = System.Web.UI.WebControls.Unit.Pixel(80);
                                    settings.Text = Model.FAdWidth == 0 ? "" : Model.FAdWidth.ToString();
                                    settings.Properties.ValidationSettings.EnableCustomValidation = true;
                                    settings.Properties.ClientSideEvents.KeyUp = "function(s,e){ widthChange(s,e)}";
                                }).GetHtml()
                                </td>
                                <td align="left" valign="middle">                                
                                    <table width="30%">
                                    <tr>
                                        <td width="10%"><img id="imgCre1" src="@Url.Content("~/Content/images/locked.gif")" alt="锁定" style="cursor: pointer" onclick="editModel(this);" /></td>
                                        <td><img id="imgCre2" src="@Url.Content("~/Content/images/reset.gif")" alt="还原" style="cursor: pointer" onclick="resetImg();" /></td>
                                    </tr>
                                </table>                 
                                </td>
                            </tr>
                            <tr>
                                <th>
                                    高:
                                </th>
                                <td align="left" class="tdClass">
                                     @Html.DevExpress().TextBox(settings =>
                                {
                                    settings.Name = "FAdHeight";
                                    settings.Width = System.Web.UI.WebControls.Unit.Pixel(80);
                                    settings.Text = Model.FAdHeight == 0 ? "" : Model.FAdHeight.ToString();
                                    settings.Properties.ValidationSettings.EnableCustomValidation = true;
                                    settings.Properties.ClientSideEvents.KeyUp = "function(s, e){ heightChange(s ,e)}";
                                }).GetHtml()
                                </td>
                            </tr>

                            <tr><td colspan="2" align="center">图片预览</td></tr>
                            <tr>                            
                                <td align="right" colspan="3">
                                <div id="divtree" style="width: 96%; height: 300px; overflow: auto; text-align: left; border: solid 1px #66CCFF;">
                                <img alt="" width="@Model.FAdWidth" height="@Model.FAdHeight" id="image" src="@Model.FSvrFileName" />
                                </div></td>                                
                             </tr>
                            </table>
                            
                </fieldset>       
            </td>
            </tr>
             <tr>
             <th></th>
                <td align="right">
                @Html.DevExpress().Button(settings =>
           {
               settings.Name = "btnOK";
               settings.Text = "确定";
               settings.ControlStyle.CssClass = "button";
               settings.Images.Image.Url = Url.Content("~/Content/ControlImages/ok.png");
               settings.ClientSideEvents.Click = "function(){ok()}";
           }).GetHtml()

                
                    @Html.DevExpress().Button(settings =>
               {
                   settings.Name = "btnCancel";
                   settings.Text = "取消";
                   settings.ControlStyle.CssClass = "button";
                   settings.Images.Image.Url = Url.Content("~/Content/ControlImages/no.png");
                   settings.CausesValidation = false;
                   settings.ClientSideEvents.Click = "cancel";
               }).GetHtml()
                </td>
            </tr>
        </table>
    @Html.Hidden("hidSaveType", "save");
    @Html.Hidden("hidAdPosition", ViewData["adPosition"]) 
    @Html.Hidden("hidMessage", ViewData["message"])
    @Html.Hidden("hdtype", ViewData["type"])
    @Html.Hidden("hidImgYWidth", ViewData["ImgYWidth"] == "" ? "0" : ViewData["ImgYWidth"])
    @Html.Hidden("hidImgYHeight", ViewData["ImgYHeight"] == "" ? "0" : ViewData["ImgYHeight"])
    @Html.Hidden("hidModel", "1")
    @Html.Hidden("hidIsClose", ViewData["IsClose"])
    @Html.Hidden("hidQP", ViewData["QP"])
    @Html.Hidden("hidRight", ViewData["right"])
    @Html.Hidden("hidLeft", ViewData["left"])

    @Html.Hidden("hdold", ViewData["old"])
    @Html.Hidden("hdsvr", ViewData["svr"])
    
    @Html.Hidden("hidAdProp", ViewData["adProp"])
}  
   
   
    <script>
        lp.Hide();
    </script>
</body>
</html>
